package com.sky.mapper.common;

import com.github.pagehelper.Page;
import com.sky.annotation.AddAnnotation;
import com.sky.annotation.UpdateAnnotation;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.pojo.Dish;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    Page<DishVO> page(DishPageQueryDTO dishPageQueryDTO);

    @Insert("insert into dish  values (null,#{name}, #{categoryId}, #{price}, #{image}, #{description}, #{status}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser}, #{makeTime})")
    @Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id")
    @AddAnnotation
    int add(Dish dish);

    DishVO findById(Long id);
    int deleteByIds(List<Long> ids);
    @Update("update dish set name = #{name}, category_id = #{categoryId}, price = #{price}, image = #{image}, description = #{description}, status = #{status}, update_time = #{updateTime}, update_user = #{updateUser}, make_time = #{makeTime} where id = #{id}")
    @UpdateAnnotation
    int update(Dish dish);
    @Update("update dish set status = #{status} where id = #{id}")
    int startOrStop(Integer status, Long id);
    @Select("select * from dish where category_id = #{categoryId}")
    List<Dish> list(Integer categoryId);
}
